<template>
  <div class="carousel-card box-radius">
    <div class="blur-img">
      <img
        class="img"
        :src="item.coverImage"
        :alt="item.title"
        loading="lazy"
        @error="handleImageError"
      >
    </div>
    <div class="carousel-info">
      <router-link
        class="info-title"
        :to="`/detail/${item.slug}?id=${item.id}`"
        :title="item.title"
        target="_blank"
      >
        {{ item.title }}
      </router-link>
      <div class="info-vs">
        <!-- 阅读量 -->
        <span class="views">
          <Icon icon="ph:fire-fill" class="icon fire" />
          {{ item.views }} 阅读
        </span>
        <!-- 分类 -->
        <span class="views">
          <Icon icon="ph:tag-fill" class="icon tag" />
          {{ item.categoryName }}
        </span>
        <!-- 评论 -->
        <span class="views">
          <Icon icon="ph:chat-circle-dots-fill" class="icon comment" />
          {{ item.commentsCount }} 评论
       </span>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { Icon } from '@iconify/vue';

const { item } = defineProps({
  item: {
    type: Object,
    required: true,
  },
});

const handleImageError = (e: Event) => {
  const target = e.target as HTMLImageElement;
  target.src = '../assets/images/fallback-image.jpg';
};
</script>

<style scoped lang="less">
.carousel-card {
  position: relative;
  display: flex;
  width: 100%;
  height: 100%;
  box-shadow: 0 3px 8px 6px rgba(7, 17, 27, 0.1);
  overflow: hidden;

  .blur-img {
    &::after {  // 添加渐变遮罩
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      background: linear-gradient(
        to bottom,
        rgba(0, 0, 0, 0.2) 0%,
        rgba(0, 0, 0, 0.4) 100%
      );
      z-index: 1;
    }

    .img {
      object-fit: cover;
      position: absolute;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
      background-position: center;
      background-size: cover;
      width: 100%;
      height: 14.5rem;
      transform: scale(1.55);
      filter: blur(1.875rem) brightness(0.75);
      transition: transform 0.6s ease; // 添加过渡效果
    }
  }

  .carousel-info {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 70px 32px;
    z-index: 10;
    box-sizing: border-box;

    .info-title {
      font-weight: 700;
      font-size: 28px;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 1;
      line-height: 1.75rem;
      letter-spacing: 0.8px; // 增加字间距
      color: #fff;
      overflow: hidden;
      cursor: pointer;
      margin: 0 auto;
      text-align: center;
      text-shadow: 0 2px 8px rgba(0, 0, 0, 0.35); // 微调阴影
      text-decoration: none;
      transition: text-shadow 0.3s ease; // 添加过渡效果

      &:hover {
        text-shadow: 0 4px 12px rgba(0, 0, 0, 0.4); // hover时增强阴影
      }
    }

    .info-vs {
      color: var(--color-white);
      margin: 0 auto;
      text-align: center;

      .views {
        display: inline-flex; // 改为 inline-flex
        align-items: center; // 垂直居中对齐
        margin-left: 20px; // 增加间距
        opacity: 0.95;
        text-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
        font-size: 14.5px; // 微调字号
        color: #ffffff;

        &:first-child {
          margin-left: 0;
        }

        // 调整图标和文字的间距
        img, span {
          margin-right: 6px;
        }

        .fire {
          margin-right: 5px;
          color: #f97316; // 橙色
        }

        .tag {
          margin-right: 5px;
          color: #ef4444; // 红色
        }

        .comment {
          margin-right: 5px;
          color: #3b82f6; // 蓝色
        }
      }
    }
  }
}

// 响应式设计保持不变
@media (max-width: 768px) {
  .carousel-card {
    .carousel-info {
      padding: 50px 20px;

      .info-title {
        font-size: 22px;
      }

      .info-vs {
        .views {
          margin-left: 8px;
          font-size: 13px;
        }
      }
    }
  }
}

@media (max-width: 576px) {
  .carousel-card {
    .carousel-info {
      padding: 40px 16px;

      .info-title {
        font-size: 18px;
      }

      .info-vs {
        .views {
          margin-left: 6px;
          font-size: 12px;
        }
      }
    }
  }
}
</style>
